#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
@Author: shijianbo
@Email:
@Time: 2023/4/11 14:35
@File: mssql.py
"""

import jaydebeapi

from .basic import DatabaseUtil



class MssqlJdbcUtil(DatabaseUtil):

    def __init__(self, user, password, ip, port=1433, **kwargs):
        self.CURSOR = {}
        driver = 'com.microsoft.sqlserver.jbdc.SQLServerDriver'
        server_name = kwargs.get('service', '')
        url = f"jdbc:sqlserver://{ip}:{port};databaseName={server_name};user={user};password={password}"
        jar_ile = kwargs.get('jar_files')
        self.db = jaydebeapi.connect(driver, url, [user, password], jar_ile)
        self.db.jconn.setAutoCommit(False)

